<template>
    <div>
        <!--  添加管理员账号页 -->
        <div class="h2">添加管理员账号</div>
        <div class="input-group">
            <div>账号：</div>
            <input v-model="user" type="text">
        </div>
        <div class="input-group">
            <div>密码：</div>
            <input v-model="password" type="password">
        </div>
        <div class="checkbox-group">
            <input v-model="is_admin" type="checkbox">
            <div>是否拥有超级管理员权限</div>
        </div>
        <div class="btn" @click="add">确认添加</div>
    </div>
</template>

<script>
    export default {
        data() {
            return {
                user:'',
                password:'',
                is_admin:false
            }
        },
        methods:{
            // 添加管理员账号
            add(){
                let {user,password,is_admin} = this
                is_admin=is_admin ? 1 : 0
                const url='admin/add_user'
                const params={uname:user,upwd:password,is_admin,user:sessionStorage.getItem('uname')}
                this.axios.post(url,params)
                    .then(res => {
                        switch (res.data.code){
                            case 200 :{
                                alert('添加管理员账号成功！')
                                break
                            }
                            case 301 :{
                                alert('你还没有该权限，请联系超级管理员')
                                break
                            }
                            default :{
                                alert('输入的格式不正确')
                            }
                        }
                    })
            }
        }
    }
</script>

<style lang="scss" scoped>
.h2 {
    font-size: 1.5em;
    padding: 20px 30px;
    border-bottom: 2px solid rgb(230, 233, 237);
    margin: 0 30px;
}
.input-group {
    margin-left: 30px;
    display: flex;
    padding-top: 15px;
    align-items: center;
    margin-bottom: 10px;
    input {
        width: 300px;
        outline: none;
        border: 1px solid #ccc;
        border-radius: 5px;
        padding: 10px 20px;
    }
}
.checkbox-group {
    display: flex;
    align-items: center;
    margin: 0 30px;
    padding-top: 10px;
    input[type="checkbox"] {
        margin-right: 15px;
    }
}
.btn {
    background-color: #26b99a;
    width: 100px;
    margin-left: 30px;
    margin-top: 20px;
    padding: 10px 0;
    text-align: center;
    color: #fff;
    border-radius: 5px;
    &:hover {
        cursor: pointer;
    }
    &:active {
        background-color: darken(#26b99a,10%);
    }
}
</style>